package controllers;

import java.awt.event.ActionEvent;
import java.io.IOException;

import boundarys.ManageCategoriesGUI;
import ccrm.ClientMain;
import entitys.Category;
import entitys.Request;
import entitys.Session;
import entitys.Type;
import enums.Command;

public class ManageCategoriesController {
	
	ManageCategoriesGUI mcc;

	public ManageCategoriesController(ManageCategoriesGUI mcc)
	{
		this.mcc=mcc;
	}
	
	/**
	 * sends request to server to get product categories list
	 */
	public static void getProductCategories()
	{
		Request r =new Request(Command.GET_PRODUCT_CATEGORIES,Session.getEmployee().getUserId());
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
	}
	
	/**
	 * sends request to server to get product categories list that contain the string text
	 * @param text
	 */
	public static void getProductCategories(String text)
	{
		Request r =new Request(Command.GET_PRODUCT_CATEGORIES_WITH_PREFIX,Session.getEmployee().getUserId(), new Category(text));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
	}
	
	/**
	 * sends request to server to add new category to the database
	 * @param category
	 * @param listamount
	 */
	public static void addCategory(String category, int listamount)
	{
		Request r =new Request(Command.ADD_CATEGORY,Session.getEmployee().getUserId(), new Category(category, listamount+1));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * sends request to server to change the product category name
	 * @param newcategory
	 * @param index
	 */
	public static void editCategory(String newcategory, int index) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.EDIT_CATEGORY,Session.getEmployee().getUserId(), new Category(newcategory, index));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * sends request to server to delete the category
	 * @param category
	 * @param index
	 */
	public static void deleteCategory(String category, int index) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.DELETE_CATEGORY,Session.getEmployee().getUserId(), new Category(category, index));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
